﻿using System;

namespace CSharpConsoleTestSolution.Demo {
    public class P26_class_extends_field_access {
        
        /**
         * 1.类的继承, 类成员的访问控制
         */
        public static void extends_test() {
            Console.WriteLine("1.类的继承, 类成员的访问控制");
            Console.WriteLine("class Car: Vehicle { ... }");
            Console.WriteLine("var type = typeof(Car);");
            Console.WriteLine("Console.WriteLine($\"type.BaseType.Name: {type.BaseType.Name}\");");
            var type = typeof(Car);
            Console.WriteLine($"type.BaseType.Name: {type.BaseType.Name}");

            Console.WriteLine();
            Console.WriteLine("单继承, 但能实现多接口");
            Console.WriteLine("sealed (相当于Java的 final, 子类不能继承),  //adj.密封的；未知的");
            Console.WriteLine("子类的访问级别 ≤ 分类的访问级别");
        }
        
        /**
         * 2.成员的继承 & 构造方法, 时间18:00
         */
        public static void field_and_constructor() {
            Console.WriteLine();
            Console.WriteLine("2.成员的继承 & 访问");
            var car = new Car();
            car.ShowOwner();
            
            Console.WriteLine();
            Console.WriteLine("//有参构造");
            Console.WriteLine("public Car(string owner) : base(owner) { }");
        }

        /**
         * 3.类成员的访问级别, 时间 39:40
         */
        public static void field_access_level() {
            Console.WriteLine();
            Console.WriteLine("3.类成员的访问级别");
        }
    }

    class Vehicle {
        public string Owner{ get; set; }
        public Vehicle() { this.Owner = "N/A"; }

        public Vehicle(string owner) { this.Owner = owner; }
    }

    class Car: Vehicle {
        public Car() { this.Owner = "Car Owner"; }
        public Car(string owner) : base(owner) { }
        
        public void ShowOwner() {
            Console.WriteLine($"this.Owner = {this.Owner}");
            Console.WriteLine($"base.Owner = {base.Owner}");
        }
    }
}